﻿
#ifndef Plane_h
#define Plane_h

#pragma region License
/*
MIT License
Copyright © 2006 The Mono.Xna Team

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma endregion License


#include <Typedef.h>
#include <Defines.h>
#include <CSharpPropertyMethods.h>

#include <System/Object.h>
#include <System/Byte.h>
#include <System/Array.h>
#include <System/Nullable.h>
#include <System/Math.h>
#include <System/Generic/IEquatable.h>
#include <System/Collections/Generic/IEnumerable.h>
#include <System/ArgumentOutOfRangeException.h>
#include <System/ArgumentNullException.h>
#include <System/ArgumentException.h>

#include <Riccsson/Xna/Framework/Vector3.h>
#include <Riccsson/Xna/Framework/Vector4.h>
#include <Riccsson/Xna/Framework/RMatrix.h>
#include <Riccsson/Xna/Framework/ContainmentType.h>
#include <Riccsson/Xna/Framework/PlaneIntersectionType.h>

namespace Riccsson
{
	namespace Xna
	{
		namespace Framework
		{
			// Forward declerations.
			struct BoundingBox;
			struct BoundingSphere;
			struct BoundingFrustum;
	
	        /*internal*/ class PlaneHelper
            {
                /// <summary>
                /// Returns a value indicating what side (positive/negative) of a plane a point is
                /// </summary>
                /// <param name="point">The point to check with</param>
                /// <param name="plane">The plane to check against</param>
                /// <returns>Greater than zero if on the positive side, less than zero if on the negative size, 0 otherwise</returns>
                public: static float ClassifyPoint(Vector3 ref point, Plane ref plane);

                /// <summary>
                /// Returns the perpendicular distance from a point to a plane
                /// </summary>
                /// <param name="point">The point to check</param>
                /// <param name="plane">The place to check</param>
                /// <returns>The perpendicular distance from the point to the plane</returns>
                public: static float PerpendicularDistance(Vector3 ref point, Plane ref plane);
            };

            struct Plane
				: public Riccsson::System::Generic::IEquatable<Plane>
            {
                #pragma region public: Fields

                public: float D;
                public: Vector3 Normal;

                #pragma endregion public: Fields


                #pragma region Constructors

				public: Plane();

                public: Plane(Vector4 value);

                public: Plane(Vector3 normal, float d);

                public: Plane(Vector3 a, Vector3 b, Vector3 c);

                public: Plane(float a, float b, float c, float d);

                #pragma endregion Constructors


                #pragma region public: Methods

                public: float Dot(Vector4 value);
						
                public: void Dot(Vector4 ref value, float out result);

                public: float DotCoordinate(Vector3 value);

                public: void DotCoordinate(Vector3 ref value, float out result);

                public: float DotNormal(Vector3 value);

                public: void DotNormal(Vector3 ref value, float out result);

                public: static void Transform(Plane ref plane, Quaternion ref rotation, Plane out result);

                public: static void Transform(Plane ref plane, Matrix ref matrix, Plane out result);

                public: static Plane Transform(Plane plane, Quaternion rotation);

                public: static Plane Transform(Plane plane, Matrix matrix);

                public: void Normalize();

                public: static Plane Normalize(Plane value);

                public: static void Normalize(Plane ref value, Plane out result);

				public: override bool Equals(Riccsson::System::object* other);

                public: bool Equals(Plane* other);

                public: override int GetHashCode();

                public: PlaneIntersectionType Intersects(BoundingBox& box);

                public: void Intersects(BoundingBox ref box, PlaneIntersectionType out result);

                public: PlaneIntersectionType Intersects(BoundingFrustum& frustum);

                public: PlaneIntersectionType Intersects(BoundingSphere& sphere);

                public: void Intersects(BoundingSphere ref sphere, PlaneIntersectionType out result);

				public: override GC_PTR<Riccsson::System::string> ToString();

                #pragma endregion
            };

            inline bool operator !=(Plane plane1, Plane plane2)
            {
                return !plane1.Equals(&plane2);
            }

            inline bool operator ==(Plane plane1, Plane plane2)
            {
                return plane1.Equals(&plane2);
            }
        }
	}
}

#endif
